<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>视频课程</title>
    <?php require 'templates/common/head.html'; ?>
    <style type="text/css">
        .divleft{width: 14%; float: left; border-right: solid 1px #d5d5d5; margin-right: 1% }
        .divleft2{width: 4.5%; float: left;  border-right: solid 1px #d5d5d5; margin-right: 1% }
        .divleft3{width: 8%; float: left;  border-right: solid 1px #d5d5d5; margin-right: 1% }
        .divleft4{width: 3.5%; float: left;  border-right: solid 1px #d5d5d5; margin-right: 1% }
        .divright{ width: 12%; float:left; }
    </style>
</head>
<body>

<div class="container-fluid">
    <?php require 'templates/common/nav.html'; ?>
    <div class="panel panel-primary">
        <div class="panel-heading text-center"><h3 class="panel-title">管理视频课程</h3></div>
        <div class="panel-group"  id="accordion" role="tablist" aria-multiselectable="true">
            <div class="panel-heading text-right">
                <a href="index.php?m=video_course&a=frequency_count" type="button" class="btn btn-primary">听课频率统计</a>
                <a href="index.php?m=video_course&a=addVideo" type="button" class="btn btn-primary">添加视频课程</a>
            </div>
            <div class="panel-heading text-right">
                测试openID: <input type="text" id="oid">
            </div>
            <div class="panel panel-default">
                <div class="panel-heading" style="background-color:#d5d5d5">
                    <div class="row" >

                        <div class="divleft" style="text-align:center">主题</div>
                        <div class="divleft" style="text-align:center">标题</div>
                        <div class="divleft2" style="text-align:center">讲课专家</div>
                        <div class="divleft4" style="text-align:center">状态</div>
                        <div class="divleft4" style="text-align:center">发送</div>
                        <div class="divleft2" style="text-align:center">关注人数</div>
                        <div class="divleft2" style="text-align:center">阅读人数</div>
                        <div class="divleft4" style="text-align:center">阅读量</div>
                        <div class="divleft2" style="text-align:center">在线人数</div>
                        <div class="divleft4" style="text-align:center">留言数</div>
                        <div class="divleft3" style="text-align:center">开始时间</div>
                        <div class="divleft3" style="text-align:center">结束时间</div>
                        <div class="divright" style="text-align:center">操作</div>
                    </div>
                </div>
            </div>
            <?php foreach($videoCourses as $v):?>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="row" >

                            <div class="divleft" style="text-align:center">
                                <?= $v['theme']?><span style="color: red;"><?php if($v['is_test']==1) echo '(测试数据)';   ?></span>&nbsp;
                            </div>
                            <div class="divleft" style="text-align:center">
                                <a href="<?= $v['视频url']?>"><?= $v['title']?></a>&nbsp;
                            </div>
                            <div class="divleft2" style="text-align:center">
                                <?=$v['name']?>&nbsp;
                            </div>
                            <div class="divleft4" style="text-align:center">
                                <?=$v['状态']?>&nbsp;
                            </div>
                            <div class="divleft4" style="text-align:center">
                                <?=$v['发送']?>&nbsp;
                            </div>
                            <div class="divleft2" style="text-align:center">
                                <?=$v['num']?>&nbsp;
                            </div>
                            <div class="divleft2" style="text-align:center">
                                <?=$v['comment_num']?>&nbsp;
                            </div>
                            <div class="divleft4" style="text-align:center">
                                <?=$v['浏览次数']?>&nbsp;
                            </div>
                            <div class="divleft2" style="text-align:center">
                                <a href="index.php?m=video_course&a=show_online_user&type=1&gid=<?=$v['群id']?>" title="历史在线人数"><?=$v['online_num']?></a> &nbsp;| &nbsp;<a href="index.php?m=video_course&a=show_online_user&type=2&gid=<?=$v['群id']?>" title="实时在线人数"><?=$v['real_time_online']?></a>&nbsp;
                            </div>
                            <div class="divleft4" style="text-align:center">
                               <a href="index.php?m=group_manage&a=view_chat_logs&id=<?=$v['群id']?>" title="留言数"><?=$v['chat_num']?></a>&nbsp;
                            </div>
                            <div class="divleft3" style="text-align:center">
                                <?=$v['开始时间']?>
                            </div>
                            <div class="divleft3" style="text-align:center">
                                <?=$v['结束时间']?>
                            </div>
                            <div class="divright" style="text-align:center">
                                <!--<button onclick="ceshi('<?=$v['id']?>')" class="btn btn-primary btn-xs">测试</button>-->
                                <a class="btn btn-primary btn-xs" href="index.php?m=video_course&a=addVideo&id=<?=$v['id']?>">编辑</a>
                                <a href="index.php?m=video_course&a=focus_user_detail&id=<?=$v['id']?>&title=<?= $v['title']?>"  class="btn btn-primary btn-xs">查看</a></b>

                                <button onclick="disabled=true;tuisong('<?=$v['id']?>')" class="btn btn-primary btn-xs">推送</button>
                                <button onclick="disabled=true;keQian_tuisong('<?=$v['id']?>')" class="btn btn-primary btn-xs">课前推送</button>
                                <!--视频开始一个小时后， 视频结束后才能编辑内容-->
                                <?php if($v['状态'] =='预备'):?>
                                    <button onclick="f修改课程状态('开始',<?=$v['id']?>)" class="btn btn-primary btn-xs">开始上课</button>
                                <?php endif;?>

                                <!--视频开始一个小时后， 视频结束后才能编辑内容-->
                                <?php if($v['状态'] =='开始'):?>
                                    <button onclick="f修改课程状态('结束',<?=$v['id']?>)" class="btn btn-primary btn-xs">结束上课</button>
                                <?php endif;?>
                            </div>

                        </div>
                    </div>
                </div>
                <?php endforeach;?>
        </div>
        <div><?= $page->showpage();?></div>
    </div>


</div>
<?php require 'templates/common/foot.html'; ?>
</body>
</html>
<script language="JavaScript">
    //测试推送
    function ceshi(id){
        var oid=$("#oid").val();
        if(oid){
            $.post('index.php?m=video_course&a=send_course',{'id':id,'oid':oid},function(data){

                alert("测试通过");
                location.reload();
            });
        }else{
            alert('请填写oid');
        }

    }
    //正式推送课程
    function tuisong(id){
        var oid=$("#oid").val();
        if(oid){
            var res = confirm("您确定给’"+oid+"’推送课程吗?");
        }else{
            var res = confirm("您确定给全部用户推送课程吗？");
        }
        if(res) {
            $.post('index.php?m=video_course&a=send_course', {'id': id, 'oid': oid}, function (data) {

                alert("推送成功");
                location.reload();
            });
        }
    }
    //开课前推送
    function keQian_tuisong(id){
        var oid=$("#oid").val();
        if(oid){
            var res = confirm("您确定给’"+oid+"’课前推送吗?");
        }else{
            var res = confirm("您确定给全部用户课前推送吗？");
        }
        if(res) {
            $.post('index.php?m=video_course&a=push_before_class', {'id': id, 'oid': oid}, function (data) {

                alert("推送成功");
                location.reload();
            });
        }
    }

    function f修改课程状态(状态,id){
        $.post('index.php?m=video_course&a=update_course_status',{'课程id':id,"状态":状态},function(data){
            if(data){
                alert(状态+"课程成功!");
                location.replace(location.href);
            }else {
                alert(状态+"课程失败!");
            }
        });
    }
</script>
